package com.fox.stock.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {

    /**
     * 重新定义消息序列化的方式,改为基于json格式序列化和反序列化(原本自带的又臭又长,用户看不懂)
     * @return
     */
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }


    // TODO: 各个信息队列

    /**
     * 国内大盘的信息队列
     * @return
     */
    @Bean
    public Queue innerMarketQueue(){
        return new Queue("innerMarketQueue",true);
    }

    /**
     * 个股板块信息队列
     * @return
     */
    @Bean
    public Queue blockRtInfoQueue(){
        return new Queue("blockRtInfoQueue",true);
    }




    // TODO: 交换机

    /**
     * 定义大盘主题股票信息的交换机
     */
    @Bean
    public TopicExchange innerMarketTopicExchange(){
        return new TopicExchange("stockExchange",true,false);
    }

    /**
     * 定义板块主题股票信息的交换机
     */
    @Bean
    public TopicExchange blockRtInfoTopicExchange(){
        return new TopicExchange("BlockExchange",true,false);
    }


    // TODO: 绑定交换机

    /**
     * 绑定大盘信息队列到指定的交换机
     */
    @Bean
    public Binding bindingInnerMarketExchange(){
        return BindingBuilder.bind(innerMarketQueue()).to(innerMarketTopicExchange()).with("inner.market");
    }

    /**
     * 绑定板块信息队列到指定的交换机
     */
    @Bean
    public Binding bindingBlockRtInfoExchange(){
        return BindingBuilder.bind(blockRtInfoQueue()).to(blockRtInfoTopicExchange()).with("block.rt");
    }

}
